<script setup>
/*
  articleDeatil 文章详情页 - 从 pinia 中获取 currentArticle 展示文章内容
*/
import { storeToRefs } from "pinia";
import mpHtml from '@/components/mp-html/mp-html.vue'
import { ref } from "vue";
import { useForumStore } from "@/store/forum.js";
import useUserAction from "@/hooks/useUserAction";
// 处理用户行为
const { handleAction } = useUserAction()
const forumStore = useForumStore();
const { currentArticle } = storeToRefs(forumStore);
</script>

<template>
  <view class="article-detail-container">
    <!-- 头部 -->
    <view class="header">
      <!-- 标题 -->
      <view class="title-box">
        {{ currentArticle.title1 }}
      </view>
      <view class="sort-box">
        <text class="sort">#{{ currentArticle.sortName1 }}</text>
        <text class="sort">#{{ currentArticle.sortName2 }}</text>
        <text class="sort">#{{ currentArticle.sortName3 }}</text>
      </view>
      <view class="author-info">
        <view class="avatar">
          <image :src="currentArticle.authorImage" mode="scaleToFill" />
          <view class="nick-name">{{ currentArticle.authorName }}</view>
        </view>
        <view class="follow">关注</view>
      </view>
    </view>
    <!-- 文章内容 -->
    <view class="content">
      <mp-html selectable preview-img :content="currentArticle.content" />
    </view>
    <!-- 评论列表 -->
    <!-- <view class="comment-list">
      <view class="comment-item"></view>
    </view> -->

  </view>
  <!-- 用户行为 -->
  <view class="actionBox">
    <!-- 点赞 -->
    <!-- hand-up-filled -->
    <view class="action-item action-like" @click="handleAction({ actionType: 1, postId: currentArticle.id })"><uni-icons
        :type="currentArticle.actionType1 ? 'hand-up-filled' : 'hand-up'" size="20"
        :color="currentArticle.actionType1 ? '#FC84A6' : '#000'"></uni-icons>
      <text :style="{
        color: currentArticle.actionType1 ? '#FC84A6' : '#000',
        visibility: currentArticle.upvote > 0 ? 'visible' : 'hidden',
      }">
        {{ currentArticle.upvote || 0 }}
      </text>
    </view>
    <!-- 评论chat -->
     <view class="action-item" @click="handleAction({ actionType: 10086, id: currentArticle.id })"><uni-icons type="chat"
        size="20"></uni-icons></view> 
    
    <!-- 收藏 -->
    <view class="action-item" @click="handleAction({ actionType: 2, postId: currentArticle.id })"><uni-icons size="20"
        :color="currentArticle.actionType2 ? '#FECD10' : '#000'"
        :type="currentArticle.actionType2 ? 'star-filled' : 'star'"></uni-icons>
    </view>
     
    <!-- 转发 -->
    <view class="action-item" @click="handleAction({ actionType: 10086, id: currentArticle.id })"><uni-icons type="redo"
        size="20"></uni-icons></view>
  </view>
</template>

<style lang="scss" scoped>
.article-detail-container {
  padding: 0 30rpx;

  // background-color: #FAFAFA;
  .header {
    padding-top: 10rpx;
    margin-bottom: 40rpx;

    .title-box {
      font-size: 38rpx;
      font-weight: 700;
      margin-bottom: 20rpx;
      letter-spacing: 0.05em;
    }

    .sort-box {
      display: flex;
      align-items: center;
      gap: 20rpx;
      margin-bottom: 35rpx;

      .sort {
        font-size: 20rpx;
        color: rgb(66, 185, 131);
        background: rgba(66, 185, 131, 0.08);
        border: 1rpx solid rgba(66, 185, 131, 0.15);
        border-radius: 20rpx;
        padding: 6rpx 12rpx;
        letter-spacing: 0.2em;
      }
    }

    .author-info {
      display: flex;
      justify-content: space-between;
      align-items: center;

      .avatar {
        display: flex;
        align-items: center;
        gap: 20rpx;

        image {
          width: 75rpx;
          height: 75rpx;
          border-radius: 50%;
        }

        .nick-name {
          color: #888;
          font-size: 28rpx;
        }
      }

      .follow {
        font-size: 24rpx;
        color: #3b73f0;
        background: rgba(59, 115, 240, 0.08);
        border: 1rpx solid rgba(59, 115, 240, 0.15);
        border-radius: 24rpx;
        padding: 6rpx 12rpx;
        // letter-spacing:0.2em;
        display: flex;
        align-items: center;
        justify-content: center;
      }
    }
  }

  .content {
    padding: 10rpx;

    ::v-deep img {
      /* 图片最大宽度不超过容器宽度 */
      max-width: 100% !important;
      /* 高度自动按比例缩放，避免变形 */
      height: auto !important;
      /* 可选：添加图片间距 */
      margin: 10px 0;
    }

    .rich-img {
      max-width: 100% !important;
      height: auto !important;
      margin: 10px 0;
    }
  }

  .comment-list {
    padding: 1000rpx 0;
    background-color: skyblue;

    .comment-item {}
  }

}

.actionBox {
  width: 90%;
  max-width: 750rpx;
  border-radius: 999rpx;
  padding: 0 26rpx;

  background: rgba(255, 255, 255, 0.7); 
  backdrop-filter: blur(8rpx);
  -webkit-backdrop-filter: blur(8rpx);
  box-shadow: 0 6rpx 20rpx rgba(0, 0, 0, 0.12);

  position: fixed;
  z-index: 1000;
  bottom: 40rpx;
  left: 50%;
  transform: translateX(-50%);

  display: flex;
  justify-content: space-between;
  align-items: center;

  .action-item {
    width: 100rpx;
    height: 100rpx;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;

    transition: transform 0.15s ease;

    &:active {
      transform: scale(0.88);
    }

    text {
      margin-left: 6rpx;
      font-size: 26rpx;
      font-weight: 500;
      color: #333;
    }
  }

  .action-like {
    width: 120rpx;
    display: flex;
    // justify-content: space-between;
    align-items: center;

    uni-icons {
      margin-right: 4rpx;
    }
  }
}
</style>
